package com.example.lcode.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Question784 {

    public List<String> letterCasePermutation(String s) {
        List<String> result = new ArrayList<>();
        String subRes = new String();
        int startIndex = 0;
        letterCasePermutation(s, result, subRes, startIndex);
        return result;
    }

    private void letterCasePermutation(String str, List<String> result, String subRes, int startIndex) {
        if (str.length() == subRes.length()) {
            result.add(new String(subRes.toString()));
            return;
        }
        for (int i = startIndex; i < str.length(); i++) {
            char chart = str.charAt(i);
            String strChar = String.valueOf(str.charAt(i));
            if ('a' <=  chart && chart <= 'z') {
                letterCasePermutation(str, result, subRes + strChar, i + 1);
                letterCasePermutation(str, result, subRes + strChar.toUpperCase(), i + 1);
            } else if ('A' <=  chart && chart <= 'Z') {
                letterCasePermutation(str, result, subRes + strChar, i + 1);
                letterCasePermutation(str, result, subRes + strChar.toLowerCase(), i + 1);
            } else {
                letterCasePermutation(str, result, subRes + strChar, i + 1);
            }
        }
    }

    public static void main(String[] args) {
        Question784 question784 = new Question784();
        List<String> list = question784.letterCasePermutation("12345");
        System.out.println(list);
    }

}
